package com.media.themovieworld.util;

import java.text.NumberFormat;
import java.text.ParsePosition;

import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class CommonUtil {

	public static boolean isNumeric(String str)
	{
	  NumberFormat formatter = NumberFormat.getInstance();
	  ParsePosition pos = new ParsePosition(0);
	  formatter.parse(str, pos);
	  return str.length() == pos.getIndex();
	}
	
	public static String convertToTimeString(String time){
		if(time == null || time.equals("") || !isNumeric(time)) return "00:00:00";
		int minutes = Integer.valueOf(time);
		int hoursTime = minutes/60;
		int minutesTime = (minutes - hoursTime*60);
		String strHour = String.valueOf(hoursTime);
		String strMinute = String.valueOf(minutesTime);
		if(hoursTime<10) strHour = "0"+hoursTime;
		if(minutesTime<10) strMinute = "0"+minutesTime;
		return strHour+":"+strMinute+":00";
	}
	
    // Displays a Toast popup
    static void makeToast(Context context, String message) {
        int duration = Toast.LENGTH_SHORT;
        Toast toast = Toast.makeText(context, message, duration);
        toast.show();
    }
}
